/*
day225_2
2020.4.9
*/
#include<iostream>
#include<vector>
using namespace std;

struct TreeNode {
	int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
    	int cur=0;
        return help(preorder,inorder,cur,0,inorder.size()-1);
    }
    
    TreeNode* help(vector<int>& preorder, vector<int>& inorder,int &cur,int l,int r)
    {
    	if(l>r)
    	{
    		return NULL;
		}
		int cur_val=preorder[cur++];
		int i=l;
		while(i<=r && inorder[i]!=cur_val) ++i;
		TreeNode *tem=new TreeNode(cur_val);
		tem->left=help(preorder,inorder,cur,l,i-1);
		tem->right=help(preorder,inorder,cur,i+1,r);
		
		return tem;
	}
};

int main()
{
	return 0;
}
